package pattern.composite

/**
 * Created by root on 15-9-18.
 */
object Client {

  def main(args: Array[String]) {
    // 生成树根，并为其增加两个叶子节点
    val root = new Composite("Root");
    root.add(new Leaf("Leaf A in Root"));
    root.add(new Leaf("Leaf B in Root"));

    // 为根增加两个枝节点
    val branchX = new Composite("Branch X in Root");
    val branchY = new Composite("Branch Y in Root");
    root.add(branchX);
    root.add(branchY);

    // 为BranchX增加页节点
    branchX.add(new Leaf("Leaf A in Branch X"));

    // 为BranchX增加枝节点
    val branchZ = new Composite("Branch Z in Branch X");
    branchX.add(branchZ);

    // 为BranchY增加叶节点
    branchY.add(new Leaf("Leaf in Branch Y"));

    // 为BranchZ增加叶节点
    branchZ.add(new Leaf("Leaf in Branch Z"));

    // 显示树
    root.display(1);
  }
}
